"""
人脸检测
"""
import cv2
from yolo_face_detect import YOLO_face
class FaceDetect:
    def __init__(self):
        self.yolo_face = YOLO_face('weights/yolo_face.onnx')

    def detect(self, frame):
        """
        人脸检测
        :param frame:被检测的图像
        :return:人脸的矩形区域
        """
        if frame is None:
            print('NO Photo')
            return
        det_bboxes, det_conf, det_classid, landmarks = self.yolo_face.detect(frame)
        for box in det_bboxes:
            # print(box)
            x, y, w, h = box.astype('int')
            cv2.rectangle(frame,
                          (x, y),
                          (x + w, y + h),
                          color=(0, 255, 0),
                          thickness=2)
            # HWC 怎么截取
            face_img = frame[y:y+h,x:x+w]
            return face_img
